
/* -*- C++ -*- */

//=============================================================================
/*
* @author Feloweria <380374483@qq.com>
* Copyright (C) Feloweria
*
* $ID 2014-05-14 11:26:14 AM
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
* @version 1.0
*/
//=============================================================================

#ifndef FLOWRIA_SOCKET_BUFFER_INCLUDE
#define FLOWRIA_SOCKET_BUFFER_INCLUDE

#include "IO/InputStream.h"
#include "IO/OutputStream.h"

FELOWRIA_BEGIN

class Socket;

class DLL_EXPORT SocketBuffer : public InputStream, public OutputStream
{
public:
	SocketBuffer(char *buffer, char *buffer_end);
	~SocketBuffer();

public:
	virtual int32 Readable() const;
	virtual void Readable(char *&rdPtr, int32 &size);

	virtual int32 Writable() const;
	virtual void Writable(char *&wdPtr, int32 &size);

public:
	virtual bool Write(const char *bytes, uint32 size);
	virtual bool WritePeek(const char *bytes, uint32 size);
	virtual bool WriteSkip(uint32 size);

	virtual bool Read(char *bytes, uint32 size);
	virtual bool ReadPeek(char *bytes, uint32 size);
	virtual bool ReadSkip(uint32 size);

public:
	virtual int32 WriteSize() const;
	virtual int32 ReadSize() const;

public:
	void Reset();

protected:
	char *buffer;
	char *buffer_end;

	char *data;
	char *data_end;
};

FELOWRIA_END

#include "SocketBuffer.inl"


#endif //FLOWRIA_SOCKET_BUFFER_INCLUDE
